package Control;

import Model.student;
import Service.Updateservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/one")
public class selectonestudentControl extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Updateservice updateservice = new Updateservice();
        String id = req.getParameter("id");
        Integer id1 = Integer.valueOf(id);
        try {
            student student = updateservice.selectOneService(id1);
            Integer id2 = student.getId();
            String name = student.getName();
            Integer age = student.getAge();
            String height = student.getHeight();
            String school = student.getSchool();
            resp.setContentType("text/html;charset=utf-8");
            PrintWriter writer = resp.getWriter();
            writer.write("<html>");
            writer.write("<head>");
            writer.write("<title>学生数据展示</title>");
            writer.write("<meta charset=utf-8>");
            writer.write("</head>");
            writer.write("<body style='background:pink'>");
            writer.write("<div style='width:1000px;margin:0 auto; text-align:center'>");
            writer.write("<h1>学生数据修改</h1>");
            writer.write("<form role='form' method='post' action='update'>");
            writer.write("<div class='form-group'>");
            writer.write("<label for='name'>id<label>");
//            disabled
            writer.write("<input readonly=\"readonly\" type='text' class='form-control' value='"+id2+"' name='id' id='id' placeholder='请输入id'");
            writer.write("<div>");
            writer.write("<div class='form-group'>");
            writer.write("<label for='name'>name<label>");
            writer.write("<input type='text' class='form-control' value='"+name+"' name='name' id='name' placeholder='请输入name'");
            writer.write("<div>");
            writer.write("<div class='form-group'>");
            writer.write("<label for='name'>age<label>");
            writer.write("<input type='text' class='form-control' value='"+age+"' name='age' id='age' placeholder='请输入age'");
            writer.write("<div>");
            writer.write("<div class='form-group'>");
            writer.write("<label for='name'>height<label>");
            writer.write("<input type='text' class='form-control' value='"+height+"' name='height' id='height' placeholder='请输入height'");
            writer.write("<div>");
            writer.write("<div class='form-group'>");
            writer.write("<label for='name'>school<label>");
            writer.write("<input type='text' class='form-control' value='"+school+"' name='school' id='school' placeholder='请输入school'");
            writer.write("<div>");
            writer.write("<button>修改<button>");
            writer.write("</form>");
            writer.write("</div>");
            writer.write("</body>");
            writer.write("</html>");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        this.doGet(req, resp);
    }
}
